package com.abel.bigwater.dataserver.model.qdies

import com.abel.bigwater.data.BcdString
import io.netty.buffer.Unpooled
import org.joda.time.DateTime
import org.junit.Assert.assertEquals
import org.junit.Test
import org.slf4j.LoggerFactory

class MainSetTimeDataTest {
    @Test
    fun testFill() {
        val buf = Unpooled.buffer()
        val p = MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.SetTime
            data = MainSetTimeData(-1).also {
                it.time = DateTime(2012, 10, 31, 11, 15, 20).toDate()
            }

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        assertEquals(DEMO_ASK_TIME, str)
    }

    companion object {
        private val lgr = LoggerFactory.getLogger(MainSetTimeDataTest::class.java)

        const val DEMO_ASK_TIME = "6812000001010712103111152003e116"
    }
}